package csci5828.configuration;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.Logger;

public class ConfigurationManager {
	
	public static final String CONFIG_FILE = "cometreviews.properties";
	private static ConfigurationManager instance;
	
	private final Logger logger = Logger.getLogger(getClass());
	private Properties props;
	
	private ConfigurationManager() {
		props = new Properties();
		try {
			InputStream is = getClass().getResourceAsStream("/"+CONFIG_FILE);
			if (is != null)
    			props.load(is);
		} catch (IOException e) {
			logger.error("Unable to load configuration from "+CONFIG_FILE);
			e.printStackTrace();
		}
	}
	
	public static synchronized ConfigurationManager getInstance() {
		if (instance == null)
			instance = new ConfigurationManager();
		return instance;
	}
	
	public String getProperty (String property, String defaultValue) {
		return props.getProperty(property, defaultValue);
	}
	
	public String getProperty (String property) {
		return props.getProperty(property);
	}
}
